﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;

namespace WebApplication3
{
    public partial class WebForm5 : System.Web.UI.Page
    {
        private void SetData(string selectCommand)
        {
            try
            {
                // Spécifie un chemin de connexion
                String connectionString = @"Data Source=.\SQLEXPRESS;AttachDbFilename='|datadirectory|\Database1.mdf';Integrated Security=True;User Instance=True";
                SqlCommand cmd = new SqlCommand();
                cmd.CommandText = selectCommand;
                SqlConnection cnx = new SqlConnection(connectionString);
                cnx.Open();
                cmd.Connection = cnx;
                cmd.ExecuteNonQuery();
                cnx.Close();


            }
            catch (SqlException)
            {
                //MessageBox.Show("Erreur Sql");
            }
        }
      

        protected void Page_Load(object sender, EventArgs e)
        {
            BirthDayMM.Attributes.Add("onKeyPress", "if (event.keyCode < 48 || event.keyCode > 57) event.returnValue = false;");
            BirthDayJJ.Attributes.Add("onKeyPress", "if (event.keyCode < 48 || event.keyCode > 57) event.returnValue = false;");
            BirthDayAAAA.Attributes.Add("onKeyPress", "if (event.keyCode < 48 || event.keyCode > 57) event.returnValue = false;");
        }

        protected void Button1_Click(object sender, EventArgs e)
        {
           
           
            int intJJ, intMM, intAA;
            intMM = Convert.ToInt32(BirthDayMM.Text);
            intMM = int.Parse(BirthDayMM.Text);
            System.Diagnostics.Debug.Write("----------------------"+intMM+"---------------------------");

            intJJ = Convert.ToInt32(BirthDayJJ.Text);
            intJJ = int.Parse(BirthDayJJ.Text);
            System.Diagnostics.Debug.Write("---------------"+intJJ+"----------------------------------");

            intAA = Convert.ToInt32(BirthDayAAAA.Text);
            intAA = int.Parse(BirthDayAAAA.Text);
            System.Diagnostics.Debug.Write("------------"+intAA+"---------------");

           
            if (intMM == 1 || intMM == 3 || intMM == 5 || intMM == 7 || intMM==8 || intMM == 9 || intMM == 11)
            {
                if (intJJ < 0 || intJJ > 31)
                {
                   
                    BirthDayJJ.BackColor = Color.Red;

                }
                else
                {
                    BirthDayJJ.BackColor = Color.White;
                }
            }

            if (intMM == 4 || intMM == 6 || intMM == 10 || intMM == 12)
            {
                if (intJJ < 0 || intJJ > 30)
                {
                    BirthDayJJ.BackColor = Color.Red;
                }
                else
                {
                    BirthDayJJ.BackColor = Color.White;
                }
            }

            if(intMM==2)
            {
                if (intJJ < 0 || intJJ > 28)
                {
                    BirthDayJJ.BackColor = Color.Red;
                }
                else
                {
                    BirthDayJJ.BackColor = Color.White;
                }
            }


            if (Name.Text.Equals("") || FirstName.Text.Equals("") || BirthDayJJ.Text.Equals("") || BirthDayMM.Text.Equals("") || BirthDayAAAA.Text.Equals("") || Adresse.Text.Equals("") || Localite.Text.Equals("") || CP.Text.Equals("") || NumTelephone.Text.Equals("") || Email.Text.Equals("") || UserName.Text.Equals("") || Password.Text.Equals("") || ConfirmPassword.Text.Equals(""))
            {


            }

            else
            {
               string date=BirthDayJJ.Text+"/"+BirthDayMM.Text+"/"+BirthDayAAAA.Text;
               setData("insert into Client (nom,prenom,datenaissance,adresse,localite,codepostal,numTelephone,[username],[password]) VALUES ('"+Name.Text+"','"+FirstName.Text+"','"+date+"','"+Adresse.Text+"','"+Localite.Text+"','"+CP.Text+"','"+NumTelephone.Text+"','"+UserName.Text+"','"+Password.Text+"')");
                //SetData("insert into Utilisateur([username],[password],type) VALUES ('" + textBox1.Text + "','" + textBox2.Text + "','" + comboBox1.Text + "')");
            }

        }

        private void setData(String selectCommand)
        {
            //String connectionString = @"Data Source=.\SQLEXPRESS;AttachDbFilename='|datadirectory|\Database1.mdf';Integrated Security=True;User Instance=True";
            try
            {
                // Spécifie un chemin de connexion
                String connectionString = @"Data Source=.\SQLEXPRESS;AttachDbFilename='|datadirectory|\Database1.mdf';Integrated Security=True;User Instance=True";
                SqlCommand cmd = new SqlCommand();
                cmd.CommandText = selectCommand;
                SqlConnection cnx = new SqlConnection(connectionString);
                cnx.Open();
                cmd.Connection = cnx;
                cmd.ExecuteNonQuery();
                cnx.Close();


            }
            catch (SqlException)
            {
                System.Diagnostics.Debug.WriteLine("Error Sql");
            }


        }




        
    }
}